﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

/// <summary>
/// Summary description for RedirectManager
/// </summary>
public class RedirectManager
{
    public static void RedirectDomainNames()
    {
        string newDomain = "infotodaylive.com";
        HttpRequest Request = HttpContext.Current.Request;
        HttpResponse Response = HttpContext.Current.Response;
        //redirecto to new
        foreach (string item in OldDomains)
        {
            if (HttpContext.Current.Request.Url.ToString().ToLower().Contains(item))
            {
                string newUrl;
                newUrl = Request.Url.ToString().Replace(item, newDomain);
                Redirect301(newUrl);
                //Redirect302(newUrl);
                break;
            }
        }

    }

    private static void Redirect301(string newUrl)
    {
        HttpContext.Current.Response.Clear();
        //
        HttpContext.Current.Response.Status = "301 Moved Permanently";
        HttpContext.Current.Response.AddHeader("Location", newUrl);
        HttpContext.Current.Response.End();
    }

    private static void Redirect302(string newUrl)
    {
        HttpContext.Current.Response.Clear();
        //
        HttpContext.Current.Response.Status = "302 Moved Temporary";
        HttpContext.Current.Response.Redirect(newUrl);
        HttpContext.Current.Response.End();
    }



    private static List<string> OldDomains
    {
        get
        {
            List<string> oldDomains = new List<string>();
            //oldDomains.Add("rsstrends.com");
            oldDomains.Add("buzzhour.com");
            oldDomains.Add("buzzonearth.com");
            oldDomains.Add("buzzminute.com");
            oldDomains.Add("forumsynd.com");
            oldDomains.Add("webbuzzinfo.com");
            oldDomains.Add("newebday.com");
            oldDomains.Add("newwebday.com");
            oldDomains.Add("newwebtime.com");            
            return oldDomains;
        }
    }
}
